package com.oracle.lingshangejia.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.bean.ConsulationDoctorBean;
import com.oracle.lingshangejia.bean.TakingRecordsBean;

import java.util.List;

public class ConsultantsDialogAdapter extends RecyclerView.Adapter<ConsultantsDialogAdapter.ViewHolder>  {
    private Context context;
    private OnItemClickListener onItemClickListener;
    private  List<ConsulationDoctorBean.DataBean> data;
    public interface  OnItemClickListener{
        void onItemClick(View view, int postion);
    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
    public  SeclectListener seclectListener;

    public void setSeclectListener(SeclectListener seclectListener) {
        this.seclectListener = seclectListener;
    }

    public interface SeclectListener{
        void select(boolean isCheck, int position);
    }
    public ConsultantsDialogAdapter(Context context, List<ConsulationDoctorBean.DataBean> data){
        this.context = context;
        this.data=data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_select_doctor,null);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        viewHolder.cb_doctor1.setText(data.get(i).getName());
        viewHolder.cb_doctor1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(seclectListener!=null){
                    seclectListener.select(viewHolder.cb_doctor1.isChecked(),i);
                }
            }
        });
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener!=null) {
                    onItemClickListener.onItemClick(viewHolder.itemView,i);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        CheckBox cb_doctor1;
        CheckBox cb_doctor2;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            cb_doctor1=itemView.findViewById(R.id.cb_doctor1);
          //  cb_doctor2=itemView.findViewById(R.id.cb_doctor2);
        }
    }
}
